package com.dkd.sbtz.service.impl;

import java.util.Date;
import java.util.List;
import com.dkd.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.dkd.sbtz.mapper.AssetCriticalMapper;
import com.dkd.sbtz.domain.AssetCritical;
import com.dkd.sbtz.service.IAssetCriticalService;

/**
 * 设备关键指标Service业务层处理
 * 
 * @author xzj
 * @date 2025-10-20
 */
@Service
public class AssetCriticalServiceImpl implements IAssetCriticalService 
{
    @Autowired
    private AssetCriticalMapper assetCriticalMapper;

    /**
     * 查询设备关键指标
     * 
     * @param id 设备关键指标主键
     * @return 设备关键指标
     */
    @Override
    public AssetCritical selectAssetCriticalById(Long id)
    {
        return assetCriticalMapper.selectAssetCriticalById(id);
    }

    /**
     * 查询设备关键指标列表
     * 
     * @param assetCritical 设备关键指标
     * @return 设备关键指标
     */
    @Override
    public List<AssetCritical> selectAssetCriticalList(AssetCritical assetCritical)
    {
        return assetCriticalMapper.selectAssetCriticalList(assetCritical);
    }

    /**
     * 新增设备关键指标
     * 
     * @param assetCritical 设备关键指标
     * @return 结果
     */
    @Override
    public int insertAssetCritical(AssetCritical assetCritical)
    {
        assetCritical.setCreateTime(DateUtils.getNowDate());
        return assetCriticalMapper.insertAssetCritical(assetCritical);
    }

    /**
     * 修改设备关键指标
     * 
     * @param assetCritical 设备关键指标
     * @return 结果
     */
    @Override
    public int updateAssetCritical(AssetCritical assetCritical)
    {
        assetCritical.setUpdateTime(DateUtils.getNowDate());
        return assetCriticalMapper.updateAssetCritical(assetCritical);
    }

    /**
     * 批量删除设备关键指标
     * 
     * @param ids 需要删除的设备关键指标主键
     * @return 结果
     */
    @Override
    public int deleteAssetCriticalByIds(Long[] ids)
    {
        return assetCriticalMapper.deleteAssetCriticalByIds(ids);
    }

    /**
     * 删除设备关键指标信息
     * 
     * @param id 设备关键指标主键
     * @return 结果
     */
    @Override
    public int deleteAssetCriticalById(Long id)
    {
        return assetCriticalMapper.deleteAssetCriticalById(id);
    }

    @Override
    public int insertBatch(List<AssetCritical> list) {
        if (list == null || list.isEmpty()) {
            return 0;
        }
        // 设置默认字段（如创建时间、删除状态）
        for (AssetCritical c : list) {
            if (c.getIsDelete() == null) c.setIsDelete(0);
            if (c.getSource() == null) c.setSource(0);
            if (c.getOrderId() == null) c.setOrderId(0L);
            if (c.getCreateTime() == null) c.setCreateTime(new Date());
        }
        return assetCriticalMapper.insertBatch(list);
    }
}
